import random as rm
from scipy.stats import beta
import math as m
import numpy as np
from scipy.stats import beta

def getpoint2(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = 1 - b - d
    f = 1 - a - c
    k = 101
    alpha = 0.88
    beta = 0.88
    theta = 2.25
    delta = 0.61
    gamma = 0.69
    point_u = []
    point_v = []
    point_pi = []
    step_u = (b - a) / (k - 1)
    step_v = (d - c) / (k - 1)
    step_pi = (f - e) / (k - 1)
    for i in range(k):
        point_u.append(a + step_u * i)
        point_v.append(c + step_v * i)
        point_pi.append(e + step_pi * i)
    average = 0.5
    p = 1 / k
    possibilty = []
    for i in range(len(point_u)):
        pos = (1 / ((2 * np.pi) ** 0.5)) * np.exp(-1 * ((abs(point_u[i]) - 0.5) ** 2) / 2)
        possibilty.append(pos)
    pi1 = (p ** gamma) / (p ** gamma + (1 - p) ** gamma) ** (1 / gamma)
    pi2 = (p ** delta) / (p ** delta + (1 - p) ** delta) ** (1 / delta)
    prospect_u = [0 for i in range(k)]  # 取中间值为参考点
    d_u = [0 for i in range(k)]
    for i in range(k):
        d_u[i] = point_u[i] - average
        if (d_u[i] >= 0):
            prospect_u[i] = (d_u[i] ** alpha) * pi1
        if (d_u[i] < 0):
            prospect_u[i] = -1 * theta * ((-1 * d_u[i]) ** beta) * pi2
            # 获得每个点对应前景价值
    prospect_v = [0 for i in range(k)]  # 取中间值为参考点
    d_v = [0 for i in range(k)]
    for i in range(k):
        d_v[i] = point_v[i] - average
        if (d_v[i] >= 0):
            prospect_v[i] = 1 * (d_v[i] ** alpha) * pi1
        if (d_v[i] < 0):
            prospect_v[i] = -1 * ((-1 * d_v[i]) ** beta) * theta * pi2
    prospect_pi = [0 for i in range(k)]  # 取中间值为参考点
    d_pi = [0 for i in range(k)]
    for i in range(k):
        d_pi[i] = point_pi[i] - average
        if (d_pi[i] >= 0):
            prospect_pi[i] = (d_pi[i] ** alpha) * pi1
        if (d_pi[i] < 0):
            prospect_pi[i] = -1 * theta * ((-1 * d_pi[i]) ** beta) * pi2
    weight_u = []
    minum = -1 * theta * ((0.5) ** beta) * pi2
    p_u = [0 for i in range(k)]
    for i in range(k):
        p_u[i] = prospect_u[i] - minum
    for i in range(k):
        sum1 = sum(p_u)
        if (sum1 == 0):
            weight_u.append(1 / k)
        else:
            weight_u.append(p_u[i] / sum1)
    weight_v = []
    p_v = [0 for i in range(k)]
    for i in range(k):
        p_v[i] = prospect_v[i] - minum
    for i in range(k):
        sum4 = sum(p_v)
        if (sum4 == 0):
            weight_v.append(1 / k)
        else:
            weight_v.append(p_v[i] / sum(p_v))
    weight_pi = []
    p_pi = [0 for i in range(k)]
    for i in range(k):
        p_pi[i] = prospect_pi[i] - minum
    for i in range(k):
        sum4 = sum(p_pi)
        if (sum4 == 0):
            weight_pi.append(1 / k)
        else:
            weight_pi.append(p_pi[i] / sum(p_pi))
    value_u = []
    value_v = []
    value_pi = []
    for i in range(k):
        value_u.append(weight_u[i] * point_u[i])
        value_v.append(weight_v[i] * point_v[i])
        value_pi.append(weight_pi[i] * point_pi[i])
    u = sum(value_u)
    v = sum(value_v)
    pi = sum(value_pi)
    # score11 = m.log((m.exp(2 * (u - v)) / ((1 - (a + b + c + d) / 2 + u + v))) ** 0.5, np.exp(1))
    # score =(m.exp(2*((u-v)+u*(1-u-v)))/(1+(1-u-v)))**(1/2)
    # score12 = m.log((m.exp(2 * (u - v)) / ((1 + 0.5 * (a + b + c + d)) / 2)) ** 0.5, np.exp(1))
    # score=(u-v+1)/((1 + 0.5 * (a + b + c + d)) / 2)
    # score = (m.exp(2 * (u - v) ) / (1 + pi)) ** 0.5
    # score1=m.log((m.exp(2 * (u - v)) / (1 + pi)) ** 0.5, np.exp(1))
    score1 = m.log((m.exp(2 * (u - v)) / (1 + (1 - a - c + 1 - b - d) / 2)) ** 0.5, np.exp(1))
    # score2 = m.log((m.exp(u - v) / (1 + pi)), np.exp(1))
    # score9 = m.log((m.exp(2 * (u - v)) / ((1 + 0.5 * (a + b + c + d)) / 2)) ** 0.5, np.exp(1))
    # print(a,b,c,d,score1)
    return score1


def getpoint0(IVq_ROF, q):
    '''
    正态分布
    :param IVq_ROF:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = 1 - b - d
    f = 1 - a - c
    k = 21
    alpha = 0.88
    beta = 0.88
    theta = 2.25
    delta = 0.61
    gamma = 0.69
    point_u = []
    point_v = []
    point_pi = []
    step_u = (b - a) / (k - 1)
    step_v = (d - c) / (k - 1)
    step_pi = (f - e) / (k - 1)
    for i in range(k):
        point_u.append(a + step_u * i)
        point_v.append(c + step_v * i)
        point_pi.append(e + step_pi * i)
    average = 0.5
    possibilty_u = []
    possibilty_v = []
    possibilty_pi = []
    for i in range(len(point_u)):
        pos_u = (1 / ((2 * np.pi) ** 0.5)) * np.exp(-1 * ((abs(point_u[i]) - 0.5) ** 2) / 2)
        possibilty_u.append(pos_u)
        pos_v = (1 / ((2 * np.pi) ** 0.5)) * np.exp(-1 * ((abs(point_v[i]) - 0.5) ** 2) / 2)
        possibilty_v.append(pos_v)
        pos_pi = (1 / ((2 * np.pi) ** 0.5)) * np.exp(-1 * ((abs(point_pi[i]) - 0.5) ** 2) / 2)
        possibilty_pi.append(pos_pi)
    prospect_u = [0 for i in range(k)]  # 取中间值为参考点
    d_u = [0 for i in range(k)]
    for i in range(k):
        p = possibilty_u[i]
        pi1_u = (p ** gamma) / (p ** gamma + (1 - p) ** gamma) ** (1 / gamma)
        pi2_u = (p ** delta) / (p ** delta + (1 - p) ** delta) ** (1 / delta)
        d_u[i] = point_u[i] - average
        if (d_u[i] >= 0):
            prospect_u[i] = (d_u[i] ** alpha) * pi1_u
        if (d_u[i] < 0):
            prospect_u[i] = -1 * theta * ((-1 * d_u[i]) ** beta) * pi2_u
            # 获得每个点对应前景价值
    prospect_v = [0 for i in range(k)]  # 取中间值为参考点
    d_v = [0 for i in range(k)]
    for i in range(k):
        p = possibilty_v[i]
        pi1_v = (p ** gamma) / (p ** gamma + (1 - p) ** gamma) ** (1 / gamma)
        pi2_v = (p ** delta) / (p ** delta + (1 - p) ** delta) ** (1 / delta)
        d_v[i] = point_v[i] - average
        if (d_v[i] >= 0):
            prospect_v[i] = 1 * (d_v[i] ** alpha) * pi1_v
        if (d_v[i] < 0):
            prospect_v[i] = -1 * ((-1 * d_v[i]) ** beta) * theta * pi2_v
    prospect_pi = [0 for i in range(k)]  # 取中间值为参考点
    d_pi = [0 for i in range(k)]
    for i in range(k):
        p = possibilty_pi[i]
        pi1_pi = (p ** gamma) / (p ** gamma + (1 - p) ** gamma) ** (1 / gamma)
        pi2_pi = (p ** delta) / (p ** delta + (1 - p) ** delta) ** (1 / delta)
        d_pi[i] = point_pi[i] - average
        if (d_pi[i] >= 0):
            prospect_pi[i] = (d_pi[i] ** alpha) * pi1_pi
        if (d_pi[i] < 0):
            prospect_pi[i] = -1 * theta * ((-1 * d_pi[i]) ** beta) * pi2_pi
    weight_u = []
    pos = (1 / ((2 * np.pi) ** 0.5)) * np.exp(-1 * ((0 - 0.5) ** 2) / 2)
    minum = -1 * 2.25 * ((0.5) ** 0.88) * ((pos ** 0.69) / (pos ** 0.69 + (1 - pos) ** 0.69) ** (1 / 0.69))
    p_u = [0 for i in range(k)]
    for i in range(k):
        p_u[i] = prospect_u[i] - minum
    for i in range(k):
        sum1 = sum(p_u)
        if (sum1 == 0):
            weight_u.append(1 / k)
        else:
            weight_u.append(p_u[i] / sum1)
    weight_v = []
    p_v = [0 for i in range(k)]
    for i in range(k):
        p_v[i] = prospect_v[i] - minum
    for i in range(k):
        sum4 = sum(p_v)
        if (sum4 == 0):
            weight_v.append(1 / k)
        else:
            weight_v.append(p_v[i] / sum(p_v))
    weight_pi = []
    p_pi = [0 for i in range(k)]
    for i in range(k):
        p_pi[i] = prospect_pi[i] - minum
    for i in range(k):
        sum4 = sum(p_pi)
        if (sum4 == 0):
            weight_pi.append(1 / k)
        else:
            weight_pi.append(p_pi[i] / sum(p_pi))
    value_u = []
    value_v = []
    value_pi = []
    for i in range(k):
        value_u.append(weight_u[i] * point_u[i])
        value_v.append(weight_v[i] * point_v[i])
        value_pi.append(weight_pi[i] * point_pi[i])
    u = sum(value_u)
    v = sum(value_v)
    pi = sum(value_pi)
    score = m.log((m.exp(2 * (u - v)) / (1 + pi)) ** 0.5, np.exp(1))
    return score


def getpoint1(IVq_ROF):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (m.log(a + b + c + d + 1) + 2 * (a - c + b - d) + ((b - a) + (d - c)) + (c + b - a - d) - np.sign(
        a + b + c + d) * (m.log(3))) / 4
    return score


def f0(IVq_ROF, q):
    '''
    :param IVq_ROF: 广义正交数
    :param q:
     :return:
    '''
    a = IVq_ROF[0][0] ** q
    b = IVq_ROF[0][1] ** q
    c = IVq_ROF[1][0] ** q
    d = IVq_ROF[1][1] ** q
    score = ((abs(a - c) ** (1 / q) + abs(b - d) ** (1 / q)) / 2) + 1
    # Accaurate=(b-a)**(1/q)+(d-c)**(1/q)
    return (score / 2)


def f1(IVq_ROF, q):
    '''
    :param IVq_ROF: 广义正交数
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = ((a + b) * (a + c) - (c + d) * (b + d)) / 2
    return score


def f2(IVq_ROF, q):
    '''

    :param IVq_ROF: 广义正交数
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = a + b * (1 - a - c) + b + a * (1 - b - d)
    return score


def f3(IVq_ROF, q):
    a = IVq_ROF[0][0] ** q
    b = IVq_ROF[0][1] ** q
    c = IVq_ROF[1][0] ** q
    d = IVq_ROF[1][1] ** q
    score = (a - c) * ((1 - a - c) ** (1 / q)) + (b - d) * ((1 - b - d) ** (1 / q)) + abs(a - c) + abs(b - d)
    return score / 2


def f4(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (1 / 2) * (a ** q + b ** q - c ** q - d ** q)
    return (score + 1) / 2


def f5(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = a - c + b - d + (1 - a - c ** q) ** (1 / q) + (1 - b ** q - d ** q) ** (1 / q)

    print((score) / 2)
    return (score) / 2


def f6(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    pai1 = (1 - a ** q - c ** q) ** (1 / q)
    pai2 = (1 - b ** q - d ** q) ** (1 / q)
    score = a + b + c + d + m.cos((b - a) * (m.pi / 2)) + m.cos((d - c) * (m.pi / 2)) + m.sin(
        (a - c) * (m.pi / 2)) + m.sin((b - d) * (m.pi / 2))
    score = (score - 2) / 4

    return score


'''f7==f6'''


def f7(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    if a == 0:
        pai1 = (1 - 0 - c ** q) ** (1 / q)
        pai2 = (1 - b ** q - d ** q) ** (1 / q)
    if b == 0:
        pai1 = (1 - a ** q - c ** q) ** (1 / q)
        pai2 = (1 - 0 - d ** q) ** (1 / q)
    if c == 0:
        pai1 = (1 - a ** q - 0) ** (1 / q)
        pai2 = (1 - b ** q - 0) ** (1 / q)
    if d == 0:
        pai1 = (1 - a ** q - 0) ** (1 / q)
        pai2 = (1 - b ** q - 0) ** (1 / q)

    if c != 0 and a != 0 and b != 0 and d != 0:
        pai1 = (1 - a ** q - c ** q) ** (1 / q)
        pai2 = (1 - b ** q - d ** q) ** (1 / q)
    score = ((a + b + c + d) + (pai1 + pai2)) + 4 * (
            m.cos((b + c - a - d) * (m.pi / 4)) * m.cos((d - a + 1) * (m.pi / 4)) * m.cos((c - b + 1) * (m.pi / 4)))
    # score=round(score,5)
    return (score - 4) / 4


def qTest1(IVq_ROF, q):
    '''
    1、广义正交模糊集的得分函数（2020） 只有u和v
    :param q_ROFs:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    pai = (1 - a ** q - c ** q) ** (1 / q)
    score = (m.e ** (a ** q - c ** q)) / (1 + pai ** q)
    return score


def qTest2(IVq_ROF, q):
    '''
    1、广义正交模糊集的得分函数（2020）第2种 只有u和v
    :param q_ROFs:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    pai = (1 - a ** q - c ** q) ** (1 / q)
    temp = (m.e ** (a ** q - c ** q)) / (m.e ** (a ** q - c ** q) + 1)
    score = a ** q - c ** q + (temp - 1 / 2) * (pai ** q)
    return score


def test2(IVq_ROF, q):
    '''
    2、区间值直觉模糊集的度量方法（王中兴 ，牛利利，2013年）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = 1.0 / 2 * (a ** q + b ** q - c ** q - d ** q)
    return score


def test3(IVq_ROF, q):
    '''
    3、区间值直觉模糊集的度量方法（王 中兴 ，牛利利，2013年）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    M_u = (a + b) / 2.0
    M_v = (c + d) / 2.0
    M_π = ((1 - b - d) + (1 - a - c)) / 2.0
    score = (M_u - M_v) * (1 + M_π)
    return score


def test4(IVq_ROF, q):
    '''
    4、徐泽水提出的区间值得分函数（2007）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (a - c + b - d / 2) + 1
    return score


def test5(IVq_ROF, q):
    '''
    5、Chen提出的基于集合对分析理论的得分函数（2021）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    if (a != c):
        score = (a - c) * (1 - b)
    else:
        score = a * (1 + b)
    return score


def test6(IVq_ROF, q):
    '''
    6、Chen S.M提出的得分函数（2017）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (a + b + m.sqrt(b * d) * (1 - a - c) + m.sqrt(a * c) * (1 - b - d)) / 2
    return score


def test7(IVq_ROF, q):
    '''
    7、Chen S.M提出的区间值得分函数（2021）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    temp = rm.randint(0, 1000000)
    if 0 <= b + d <= 1:
        temp = m.sqrt(a) + m.sqrt(b) + m.sqrt(1 - c) + m.sqrt(1 - d)
    score = temp / 2
    return score


def test8(IVq_ROF, q):
    '''
     8:Chen提出的基于Sin、Beta分布的得分函数（2021）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    sF_g = (a - c + b - d) / 2 + 1
    sin1 = m.sin(E_T(a, b) * m.pi / 2)
    sin2 = m.sin(E_T(b, 1 - d) * m.pi / 2)
    sin3 = m.sin(E_T(1 - d, 1 - c) * m.pi / 2)
    score = sF_g + sin1 + sin2 + sin3
    return score


def E_T(L1, L2):
    '''
    test7中用到的定义函数
    :param L1: 左边界
    :param L2: 右边界
    :return:
    '''
    # alpha = get_Beta_random_number(loc=5, scale=1, N=50)
    # beta = get_Beta_random_number(loc=5, scale=1, N=50)
    # if (alpha > beta):
    #     t = alpha
    #     beta = alpha
    #     alpha = t
    beta = 0.9
    ans = L1 + (L2 - L1) * beta
    return ans
    # a = 1   # 阿尔法
    # B = 300   # 贝塔
    # ans = L1 + (L2 - L1) * (a / (a + B))
    # return ans


def test9(IVq_ROF, q):
    '''
    9:Sengupta, T.K. Pal提出的得分函数（2000年）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # if(a==c):
    #     score=1
    # elif(a>=c>=a+d):
    temp = rm.randint(0, 1000000)
    if ((a - (a + c)) != 0):
        temp = (c - (a + d)) / (a - (a + c))
    score = max(0, temp)
    return score


def test10(IVq_ROF, q):
    '''
    10:J.A.G. Campos,提出的Beta分布得分函数
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    aerfa = 2
    beita = 3
    score = a + (b - a) * (aerfa / (aerfa + beita))
    return score


def test11(IVq_ROF, q):
    '''
    11.Cheng’s得分函数(2018)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (a - c + b - d) / 2 + 1
    return score


def test12(IVq_ROF, q):
    '''
    12.ZY. Bai提出的区间值得分函数(2013)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    temp = a + b + a * (1 - a - c) + b * (1 - b - d)
    score = temp / 2
    return score


def test13(IVq_ROF, q):
    '''
    13.Zhi-yong Bai 提出的得分函数（2013）
    14、基于trigonometric function的得分函数 少了关系式
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    temp = a + a * (1 - a - c) + b + b * (1 - b - d)
    score = temp / 2
    return score


def test14(IVq_ROF, q):
    '''
    14:基于trigonometric function的得分函数
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    S_A = ((a - c + b - d) / 2 + 1) / 2
    E_A = b - a + d - c
    H_A = a + 1 - b + c + 1 - d
    temp1 = (m.sin(S_A) / m.sin(1))
    temp2 = (m.sin(H_A) / m.sin(1))
    temp3 = (m.cos(E_A) - m.cos(1)) / (1 - m.cos(1))
    score = (temp1 * temp2 * temp3) ** (1 / 3)
    return score


def test15(IVq_ROF, q):
    '''
    15、Minkowski Weighted Score Functions of Intuitionistic Fuzzy Values (2020)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    p = 2
    tA = rm.uniform(a, b)
    fA = rm.uniform(c, d)
    score = ((tA ** p + (1 - fA) ** p) / 2) ** (1 / p)
    return score


def test16(IVq_ROF, q):
    '''
    16:Gong and Ma’s score function of the IVIFS（2019）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    add1 = (d + c - b - a) / 2
    if (a + b + c + d != 0):
        add2 = (a + b + 2 * (a * b - c * d)) / (a + b + c + d)
    score = add1 + add2
    return score


def test17(IVq_ROF, q):
    '''
    17、Wang and Chen’s score function of the IVIFS（2018）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = ((a + b) * (a + c) - (c + d) * (b + d)) / 2
    return score


def test18(IVq_ROF, q):
    '''
    18、Sahin’s accuracy function of the IVIFS（2016）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (a + b * (1 - a - c) + b + a * (1 - b - d)) / 2
    return score


def test19(IVq_ROF, q):
    '''
    19、Gao et al.’s score function of the IVIFS（2016）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = rm.randint(0, 1000000)
    if ((a + b - a * c + b * d) != 0):
        score = 1 / 4 * (a - c + b - d) * (1 + 1 / (a + b - a * c + b * d))
    return score


def test20(IVq_ROF, q):
    '''
    20、Zhang and Xu’s accuracy function of the IVIFS
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    add1 = ((a - c) + (b - d) * (1 - a - c)) / 2
    add2 = ((b - d) + (a - c) * (1 - b - d)) / 2
    score = (add1 + add2) / 2
    return score


def test21(IVq_ROF, q):
    '''
    21、彭新东提出的Information-based Score function（2020）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    add1 = 1 + a + b - c - d + 0.5 * (m.fabs(a - c) + m.fabs(b - d))
    add2 = (1 + a + c) * (m.e ** (a - c + a + b)) / (m.e ** 3) + (1 + b + d) * (m.e ** (b - d - c - d)) / m.e
    add3 = (2 - c - d) / (4 - a - b - c - d)
    score = add1 * add2 * add3 / 16
    return score


def test22(IVq_ROF, q):
    '''
    22、精确函数
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = a + b - 1 + (c + d) / 2
    return score


def test23(IVq_ROF, q):
    '''
    23、直觉的得分函数  需要a1=b1 c1=d1
    :param IFS: u,v
    :param q:
    :return:
    '''
    a1 = IVq_ROF[0][0][0]
    # b1 = IVq_ROF[0][0][1]
    c1 = IVq_ROF[0][1][0]
    # d1 = IVq_ROF[0][1][1]
    pai1 = 1 - a1 - c1

    a2 = IVq_ROF[1][0][0]
    # b2 = IVq_ROF[1][0][1]
    c2 = IVq_ROF[1][1][0]
    # d2 = IVq_ROF[1][1][1]
    pai2 = 1 - a2 - c2

    x_avg = (a1 - c1 + a2 - c2) / 2
    y_avg = (a1 + c1 + a2 + c2) / 2

    if (a1 - c1 >= x_avg):
        v1_A_1 = (a1 - c1 - x_avg) ** 0.88
    else:
        v1_A_1 = -2.25 * ((x_avg - a1 + c1) ** 0.88)

    if (a2 - c2 >= x_avg):
        v1_A_2 = (a2 - c2 - x_avg) ** 0.88
    else:
        v1_A_2 = -2.25 * ((x_avg - a2 + c2) ** 0.88)

    if (a1 - c1 >= y_avg):
        v2_A_1 = (a1 + c1 - y_avg) ** 0.88
    else:
        v2_A_1 = -2.25 * ((y_avg - a1 - c1) ** 0.88)

    if (a2 - c2 >= y_avg):
        v2_A_2 = (a2 + c2 - y_avg) ** 0.88
    else:
        v2_A_2 = -2.25 * ((y_avg - a2 - c2) ** 0.88)

    score1 = a1 - c1 + (a1 - c1 + v1_A_1 + v2_A_1) * pai1
    score2 = a2 - c2 + (a2 - c2 + v1_A_2 + v2_A_2) * pai2
    if (score1 == score2):
        return 0
    else:
        return 1

    # a = IFS[0][0]
    # c = IFS[1][0]
    # x = a-c
    # y = a+c
    # v1_A = (a-c-x)**0.88
    # v2_A = (a+c-y)**0.88
    # score = a-c+(a-c+v1_A+v2_A)*m.pi
    # return score


def test24(IVq_ROF, q):
    '''
    24、可能度得分（2016、2013等进行不同改进）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    temp = (d - a) / (c - a + d - b)
    score = max(1 - max(temp, 0), 0)
    return score


def test25(IVq_ROF, q):
    '''
    25、prospect score functio（2012）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    aerfa = 0.88
    mi_u = a + b
    ni_u = b - a
    mi_v = c + d
    ni_v = d - c
    x = (mi_u * (1 - ni_u) - mi_v * (1 - ni_v)) / (2 - ni_u - ni_v)
    y = (mi_u * (1 - ni_u) - mi_v * (1 - ni_v)) / (2 - ni_u - ni_v)
    v1_A = (((mi_u * (1 - ni_u) - mi_v * (1 - ni_v)) / (2 - ni_u - ni_v)) - x) ** aerfa
    v2_A = (((mi_u * (1 - ni_u) - mi_v * (1 - ni_v)) / (2 - ni_u - ni_v)) - x) ** aerfa
    score = a - c + b - d + (a - c + b - d + v1_A + v2_A * (f - e))
    return score


def test26(IFS, q):
    '''
    26、knowledge measure，Entropy（2020）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=u c=v
    a = IFS[0][0]
    c = IFS[1][0]
    p = 1
    KF_A = 1 / (2 ** (1 / p) + 1) * ((a ** p + c ** p + (a + c) ** p) ** (1 / p) + m.fabs(a ** p - c ** p) ** (1 / p))
    C = 500
    SF_A = (m.e ** (C * (a - c)) - 1) / (m.e ** (C * (a - c)) + 1) * KF_A
    score = SF_A
    return score


def test26_2(IVq_ROF, q):
    '''
    26、knowledge measure，Entropy（2020）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=u c=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    p = 1
    sum1 = (a ** p + b ** p + c ** p + d ** p) / 2
    sum2 = ((a + c) ** p + (b + d) ** p) / 2
    sum3 = (b ** p - d ** p + a ** p - c ** p) / 2
    KF_A = 1 / (2 ** (1 / p) + 1) * ((sum1 + sum2) ** (1 / p) + m.fabs(sum3) ** (1 / p))
    C = 500
    SF_A = (m.e ** (C * (b - d + a - c) / 2) - 1) / (m.e ** (C * (b - d + a - c) / 2) + 1) * KF_A
    score = SF_A
    return score


def test27(IVq_ROF, q):
    '''
    27、a better score function
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    sum = a + b + (1 - m.sqrt(c)) ** 2 + (1 - m.sqrt(d)) ** 2
    divide = 6 - m.sqrt(c) - m.sqrt(d) - m.sqrt(a) - m.sqrt(b)
    score = sum / divide
    return score


def test28(IVq_ROF, q):
    '''
    28、Dü˘genci’s Distance Measure-Based Method（2014）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a1 = IVq_ROF[0][0][0]
    b1 = IVq_ROF[0][0][1]
    c1 = IVq_ROF[0][1][0]
    d1 = IVq_ROF[0][1][1]

    a2 = IVq_ROF[1][0][0]
    b2 = IVq_ROF[1][0][1]
    c2 = IVq_ROF[1][1][0]
    d2 = IVq_ROF[1][1][1]

    t, p = 2, 1
    sum1 = (m.fabs(t * (a1 - a2) - (c1 - c2))) ** p
    sum2 = (m.fabs(t * (c1 - c2) - (a1 - a2))) ** p
    sum3 = (m.fabs(t * (b1 - b2) - (d1 - d2))) ** p
    sum4 = (m.fabs(t * (d1 - d2) - (b1 - b2))) ** p
    temp = 1 / 4 / ((1 + t) ** p)
    score = temp * ((sum1 + sum2 + sum3 + sum4) ** (1 / p))
    return score

    # a = IVq_ROF[0][0]
    # b = IVq_ROF[0][1]
    # c = IVq_ROF[1][0]
    # d = IVq_ROF[1][1]
    #
    # a2 = IVq_ROF[2][0]
    # b2 = IVq_ROF[2][1]
    # c2 = IVq_ROF[3][0]
    # d2 = IVq_ROF[3][1]
    # print("C2,D2")
    # print(c2,d2)
    # t = 2
    # p = 1
    # temp1 = 1/4/((1+t)**p)
    # sum1 = m.fabs(t*(a-b)-(c-d))
    # sum2 = m.fabs(t*(c-d)-(a-b))
    # sum3 = m.fabs(t*(a-b)-(c-d))
    # sum4 = m.fabs(t*(c-d)-(a-b))
    # score = temp1*((sum1**p+sum2**p+sum3**p+sum4**p))**(1/p)
    # return score


def test29(IVq_ROF, q):
    '''
    29、Zhang et al.’s [13] Entropy Measures for IvIFSs:
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    temp1 = (a - c)
    temp2 = (b - d)
    if (max(temp1, temp2) < 0):
        score = rm.randint(1, 100000)
    else:
        score = 1 / 2 * (1 - m.sqrt(max(temp1, temp2)))
    return score


def test30(IVq_ROF, q):
    '''
    30、N. Thillaigovindan, S. Anita Shanthi, J. Vadivel Naidu（2016）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    sum = a + b + (1 - m.sqrt(c)) ** 2 + (1 - m.sqrt(d)) ** 2
    pai_fu = (1 - m.sqrt(a) - m.sqrt(c)) ** 2
    pai_zheng = (1 - m.sqrt(b) - m.sqrt(d)) ** 2
    divide = 4 + m.sqrt(pai_fu) + m.sqrt(pai_zheng)
    score = sum / divide
    return score


def test31(IVq_ROF, q):
    '''
    31、Ye（2009）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    score = (a - e + b - f) / 2
    return score


def test32(IVq_ROF, q):
    '''
    32、Nayagam(2011)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = ((a - d * (1 - b)) + b - c * (1 - a)) / 2
    return score


def test33(IVq_ROF, q):
    '''
    33、Gao and Liu (2015)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    score = (a + b - c - d + 2) / (e + f + 4)
    return score


def test34(IVq_ROF, q):
    '''
    34、Sabin(2015)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    score = (a + b * e + b + a * f) / 2
    return score


def test35_a(IVq_ROF, q):
    '''
    a:Ye,2010
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (1 / (m.sqrt(2) - 1)) * (m.sqrt(2) * m.cos((a + b - c - d) / 8) * m.pi - 1)
    return score


def test35_b(IVq_ROF, q):
    '''
    b:Zhang et al,2010
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    up = min(a, c) + min(b, d)
    divided = max(a, c) + max(b, d)
    score = up / divided
    return score


def test35_c(IVq_ROF, q):
    '''
    c:wei et al,2011
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    up = min(a, c) + min(b, d) + e + f
    divided = max(a, c) + max(b, d) + e + f
    score = up / divided
    return score


def test35_d(IVq_ROF, q):
    '''
    d:zhang at al,2011
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    t = 0.5
    Ma = a + t * (b - a)
    Na = c + t * (d - c)
    score = (1 - Ma + Na) * (m.e ** (1 - Ma + Na))
    return score


def test35_e(IVq_ROF, q):
    '''
    e:Sun and Liu,2012
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    up = m.fabs(a - c) + m.fabs(b - d)
    divided = 2 + f + e + min(a + b, c + d)
    score = 1 - up / divided
    return score


def test35_f(IVq_ROF, q):
    '''
    f:Chen et al,2013
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    up = m.fabs(a - c + b - d)
    divided = 4 - a - c - b - d
    score = 1 / m.tan(m.pi / 4 + up / 4 / divided * m.pi)
    return score


def test35_g(IVq_ROF, q):
    '''
    g:Jing,2013
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    up = 2 + e + f - m.fabs(a - c) - m.fabs(b - d)
    divided = 2 + e + f
    score = up / divided
    return score


def test35_h(IVq_ROF, q):
    '''
    h:Zhang et al,2014
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = 1 - 1 / 2 * (m.fabs(b - 0.5) + m.fabs(a - 0.5) + m.fabs(d - 0.5) + m.fabs(c - 0.5))
    return score


def test35_i(IVq_ROF, q):
    '''
    i:Wei and Zhang,2015
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    pai1 = (1 - a ** q - c ** q) ** (1 / q)
    pai2 = (1 - b ** q - d ** q) ** (1 / q)
    up = m.fabs(a - c) + m.fabs(b - d)
    divided = 2 * (2 + pai2 + pai1)
    score = m.cos(up / divided * m.pi)
    return score


def test36(IVq_ROF, q):
    '''
    36、Hoang  Nguye(2015)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=b=u c=d=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # score = 1/(2*m.sqrt(2))*m.sqrt(a**2+b**2+c**2+d**2+(a+b)**2+(c+d)**2)
    score = 1 / m.sqrt(2) * m.sqrt(a ** 2 + c ** 2 + (a + c) ** 2)
    return score


def test37(IVq_ROF, q):
    '''
    37、Hoang Nguyen（2016）基于36个得分函数提出的（pass）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = 1 - 2 * m.fabs(2 * a - 0.5)
    return score


def test38(IVq_ROF, q):
    '''
    38、YingJun Zhang（2011）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=b=u c=d=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (1 - a - c) * (m.e ** (1 - a - c))
    # score = 1-(a+d)*(m.e**1-(a+d))
    return score


def test39(IVq_ROF, q):
    '''
    39、Kaihong Guo（2018）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = (1 - a ** q - c ** q) ** (1 / q)
    f = (1 - b ** q - d ** q) ** (1 / q)
    score = 1 - 1 / 2 * (1 - m.fabs(a - c) / 2 + m.fabs(b - d)) * (1 + 1 / 2 * (e + f))
    return score


def test40(IVq_ROF, q):
    '''
    40、Liu [14] dealt with the abstention group influence
    :param IFS:
    :param q:
    :return:
    '''
    # a=b=u c=d=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # score = a+a*(1-a-c)+c+c*(1-b-d)
    score = a + a * (1 - a - c)
    return score


def test41(IVq_ROF, q):
    '''
    41、Liu and Wang（分解成n等分）
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # pai1 = (1 - a ** q - c ** q) ** (1 / q)
    # pai2 = (1 - b ** q - d ** q) ** (1 / q)
    # aerfa = 0.1
    # beita = 0.5
    # score = a+(aerfa/(aerfa+beita))*pai1+c+(aerfa/(aerfa+beita))*pai2
    pai = 1 - a - c
    aerfa = 0.1
    beita = 0.1
    score = a + aerfa * pai / (aerfa + beita)
    return score


def test42(IVq_ROF, q):
    '''
    42、 Zhou and Wu [22] divided the abstention group
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # pai1 = (1 - a ** q - c ** q) ** (1 / q)
    # pai2 = (1 - b ** q - d ** q) ** (1 / q)
    # aerfa = 0.1
    # beita = 0.5
    # score = a-b+(aerfa-beita)*pai1+c-d+(aerfa-beita)*pai2
    pai = 1 - a - c
    aerfa = 0.1
    beita = 0.5
    score = a - c + (aerfa - beita) * pai
    return score


def test43(IVq_ROF, q):
    '''
    43、Lin et al. [23] introduced a new method:
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=b=u c=d=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # score = 2*a+b-1+2*c+d-1
    score = 2 * a + c - 1
    return score


def test44(IVq_ROF, q):
    '''
    44、Lin et al. [16] introduced a new score function
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # a=b=u c=d=v
    pai = 1 - a - c
    # pai1 = (1 - a ** q - c ** q) ** (1 / q)
    # pai2 = (1 - b ** q - d ** q) ** (1 / q)
    # score = 1/2*(a+c)+3/2*(1-pai1+1-pai2)-2
    score = a / 2 + 3 / 2 * (1 - pai) - 1
    return score


def test45(IVq_ROF, q):
    '''
    45、Ye [25] introduced an improved score function:
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=b=u c=d=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # score = a-c+b-d+a*(1-a-b)+c*(1-c-d)
    miu = 0.1  # 随机赋个值
    score = a - c + miu * (1 - a - c)
    return score


def test46(IVq_ROF, q):
    '''
    46、, Ye [26] introduced another improved score function
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=b=u c=d=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    pai = 1 - a - c
    score = a * (1 + pai) - pai ** 2
    return score


def test47(IVq_ROF, q):
    '''
    47、Wang and Li [18] introduced a new score function
    :param IVq_ROF:
    :param q:
    :return:
    '''
    pass


def test48(IVq_ROF, q):
    '''
    48、Prospect theory score function
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # a=b=u  c=d=v
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    pai = 1 - a - c
    x_avg = a - c
    y_avg = a + c
    aerfa = 1
    namuda = 1
    if (a - c >= x_avg):
        v1_A = (a - c - x_avg) ** aerfa
    else:
        v1_A = -namuda * ((x_avg - (a - c)) ** aerfa)

    if (a - c >= y_avg):
        v2_A = (a + c - y_avg) ** aerfa
    else:
        v2_A = -namuda * ((y_avg - (a + c)) ** aerfa)
    score = a - c + (a - c + v1_A + v2_A) * pai
    # x_avg = 1/2*(a-b+c-d)
    # y_avg = 1/2*(a+b+c+d)
    # aerfa = 1
    # k = 1
    # if(a-b>=x_avg):
    #     v1_A_1 = (a-b-x_avg)**aerfa
    # else:
    #     v1_A_1 = -k * ((x_avg - (a - b)) ** aerfa)
    # if(c-d>=x_avg):
    #     v1_A_2 = (c - d - x_avg) ** aerfa
    # else:
    #     v1_A_2 = -k * ((x_avg - (c - d)) ** aerfa)
    # if(a-b>=y_avg):
    #     v2_A_1 = (a+b-y_avg)**aerfa
    # else:
    #     v2_A_1 = -k * ((y_avg - (a + b)) * aerfa)
    # if (c-d >= y_avg):
    #     v2_A_2 = (c + d - y_avg) ** aerfa
    # else:
    #     v2_A_2 = -k * ((y_avg - (c + d)) * aerfa)
    # score = a-b+(a-b+v1_A_1+v2_A_1)*pai1+c-d+(c-d+v1_A_2+v2_A_2)*pai2
    return score


def test49(IVq_ROF, q):
    '''
    49、Wang(2006)
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # score = (3*a+3*b-c-d-1)/2
    score = (3 * a - c - 1) / 2
    return score


def test50(IVq_ROF, q):
    '''
    50 Thillaigovindan
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    sum = a + b + (1 - m.sqrt(c)) ** 2 + (1 - m.sqrt(d)) ** 2
    divide = 6 - m.sqrt(c) - m.sqrt(d) - m.sqrt(a) - m.sqrt(b)
    score = sum / divide
    return score


def test51(IVq_ROF, q):
    '''
    51、Dugenci’s  少了t和p
    :param IVq_ROF:
    :param q:
    :return:
    '''
    a1 = IVq_ROF[0][0][0]
    # b1 = IVq_ROF[0][0][1]
    c1 = IVq_ROF[0][1][0]
    # d1 = IVq_ROF[0][1][1]
    pai1 = 1 - a1 - c1

    a2 = IVq_ROF[1][0][0]
    # b2 = IVq_ROF[1][0][1]
    c2 = IVq_ROF[1][1][0]
    # d2 = IVq_ROF[1][1][1]
    pai2 = 1 - a2 - c2
    t, p = 2, 1

    score = ((0.5 / ((1 + t) ** p)) * (
                m.fabs(t * (a1 - a2) - c1 - c2) ** p + m.fabs(t * (c1 - c2) - (a1 - a2)) ** p)) ** (1 / p)
    return score
    # a = IVq_ROF[0][0]
    # b = IVq_ROF[0][1]
    # c = IVq_ROF[1][0]
    # d = IVq_ROF[1][1]
    # t = 1
    # p = 1
    # score = ((0.5/((1+t)**p))*(m.fabs(t*(a-b)-c-d)**p+m.fabs(t*(c-d)-(a-b))**p))**(1/p)
    # return score


def getpoint(IVq_ROF, q):
    a = (IVq_ROF[0][0])
    b = (IVq_ROF[0][1])
    c = (IVq_ROF[1][0])
    d = (IVq_ROF[1][1])
    while (b ** q + d ** q > 1):
        q = q + 1
        if (b ** q + d ** q <= 1):
            break
    e = (1 - b ** q - d ** q) ** (1 / q)
    f = (1 - a ** q - c ** q) ** (1 / q)
    k = 51
    alpha = 0.88
    beta = 0.88
    theta = 2.25
    delta = 0.61
    gamma = 0.69
    p = 1 / k
    pi1 = (p ** gamma) / (p ** gamma + (1 - p) ** gamma) ** (1 / gamma)
    pi2 = (p ** delta) / (p ** delta + (1 - p) ** delta) ** (1 / delta)
    point_u = []
    point_v = []
    point_pi = []
    step_u = (b - a) / (k - 1)
    step_v = (d - c) / (k - 1)
    step_pi = (f - e) / (k - 1)
    for i in range(k):
        point_u.append(a + step_u * i)
        point_v.append(c + step_v * i)
        point_pi.append(e + step_pi * i)
    average = 0.5
    prospect_u = [0 for i in range(k)]  # 取中间值为参考点
    d_u = [0 for i in range(k)]
    for i in range(k):
        d_u[i] = point_u[i] - average
        if (d_u[i] >= 0):
            prospect_u[i] = (d_u[i] ** alpha) * pi1
        if (d_u[i] < 0):
            prospect_u[i] = -1 * theta * ((-1 * d_u[i]) ** beta) * pi2
            # 获得每个点对应前景价值
    prospect_v = [0 for i in range(k)]  # 取中间值为参考点
    d_v = [0 for i in range(k)]
    for i in range(k):
        d_v[i] = point_v[i] - average
        if (d_v[i] >= 0):
            prospect_v[i] = 1 * (d_v[i] ** alpha) * pi1
        if (d_v[i] < 0):
            prospect_v[i] = -1 * ((-1 * d_v[i]) ** beta) * theta * pi2
    prospect_pi = [0 for i in range(k)]  # 取中间值为参考点
    d_pi = [0 for i in range(k)]
    for i in range(k):
        d_pi[i] = point_pi[i] - average
        if (isinstance(point_pi[i], complex)):
            print('复数', point_pi[i], a, b, c, d, e, f, q)
        if (d_pi[i] >= 0):
            prospect_pi[i] = (d_pi[i] ** alpha) * pi1
        if (d_pi[i] < 0):
            prospect_pi[i] = -1 * theta * ((-1 * d_pi[i]) ** beta) * pi2
    weight_u = []
    minum = -1 * theta * ((0.5) ** beta) * pi2
    p_u = [0 for i in range(k)]
    for i in range(k):
        p_u[i] = prospect_u[i] - minum
    for i in range(k):
        sum1 = sum(p_u)
        if (sum1 == 0):
            weight_u.append(1 / k)
        else:
            weight_u.append(p_u[i] / sum1)
    weight_v = []
    p_v = [0 for i in range(k)]
    for i in range(k):
        p_v[i] = prospect_v[i] - minum
    for i in range(k):
        sum4 = sum(p_v)
        if (sum4 == 0):
            weight_v.append(1 / k)
        else:
            weight_v.append(p_v[i] / sum(p_v))
    weight_pi = []
    p_pi = [0 for i in range(k)]
    for i in range(k):
        p_pi[i] = prospect_pi[i] - minum
    for i in range(k):
        sum4 = sum(p_pi)
        if (sum4 == 0):
            weight_pi.append(1 / k)
        else:
            weight_pi.append(p_pi[i] / sum(p_pi))
    value_u = []
    value_v = []
    value_pi = []
    for i in range(k):
        value_u.append(weight_u[i] * point_u[i])
        value_v.append(weight_v[i] * point_v[i])
        value_pi.append(weight_pi[i] * point_pi[i])
    u = sum(value_u)
    v = sum(value_v)
    pi = sum(value_pi)
    # score11 = m.log((m.exp(2 * (u - v)) / ((1 - (a + b + c + d) / 2 + u + v))) ** 0.5, np.exp(1))
    # score =(m.exp(2*((u-v)+u*(1-u-v)))/(1+(1-u-v)))**(1/2)
    score12 = m.log((m.exp(2 * (u - v)) / ((1 + 0.5 * (a + b + c + d)) / 2)) ** 0.5, np.exp(1))
    # score=(u-v+1)/((1 + 0.5 * (a + b + c + d)) / 2)
    # score = (m.exp(2 * (u - v) ) / (1 + pi)) ** 0.5
    score = m.log((m.exp(2 * (u - v)) / (1 + pi)) ** 0.5, np.exp(1))
    # if (isinstance(score, complex)):
    #     print(11111, u, v, pi,score,a,b,c,d,e,f)
    return score12


def getpoint1(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    # score = (m.exp(2 * (a- c+a*(1-a-c))) / (1 + 1 - a - c)) ** (1 / 2)
    score = (m.exp(2 * (a - c)) / (1 + a + c)) ** (1 / 2)
    return score


def sc(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = (m.log(a + b + c + d + 1) + 2 * (a - c + b - d) + ((b - a) + (d - c)) + (c + b - a - d) - np.sign(
        a + b + c + d) * (m.log(3))) / 4
    return score


def GMscore(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    A = a ** q
    B = b ** q
    C = c ** q
    D = d ** q
    score = (C + D - A - B) / 2 + (A + B + 2 * (A * B - C * D)) / (A + B + C + D)
    return score


# def GMscore(IVq_ROF,q):
#     '''
#     公式3.6Sgm
#     :param a:
#     :param b:
#     :param c:
#     :param d:
#     :param q:
#     :return:
#     '''
#     a = IVq_ROF[0][0]
#     b = IVq_ROF[0][1]
#     c = IVq_ROF[1][0]
#     d = IVq_ROF[1][1]
#     q=1
#     A = a ** q
#     B = b ** q
#     C = c ** q
#     D = d ** q
#     if(A+B+C+D==0):
#         score=0
#     else:
#         score=(A+B-C-D)/2+(A+B+2*(A*B-C*D))/(A+B+C+D)
#     return score
def mytest(IVq_ROF, q):
    '''
    52、yqp的得分函数
    :param IVq_ROF:
    :param q:
    :return:
    '''
    # 现在假设，我们有1000个点
    # 第一步：给出两个区间(u1,u2)(v1,v2) 和 （u1,u2)(v1,v2)
    # 我的思路，就是每个权重/总的权重(e),这样相加为1，再乘上beta分布，越靠近区间中间beta函数值越大
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    pai1 = (1 - a ** q - c ** q) ** (1 / q)
    pai2 = (1 - b ** q - d ** q) ** (1 / q)
    SF_g = (a - c + b - d) / 2 + 1
    score2 = get_score(a, b)
    score3 = get_score(b, 1 - d)
    score4 = get_score(c, d)
    score = SF_g + score2 + score3 + score4
    return score


factorial = [1]  # 1/n!


# 初始化阶乘
def fac():
    global factorial
    for i in range(1, 21):
        temp = 1
        for j in range(1, i + 1):
            temp *= j
        factorial.append(temp)
    # n！= √2πn*(n/e)**n
    for i in range(21, 101):
        tem = int(m.sqrt(2 * m.pi * i) * ((i / m.e) ** i))
        factorial.append(tem)


def get_e(times):
    sum = 1
    # 求和1/n!
    for i in range(1, times + 1):
        temp = factorial[i]
        sum += 1 / temp
    return sum


def get_alpha_beta(left, right):
    avg = (right - left) / 2
    avg = round(avg, 2)
    alpha = avg * 100
    beta = 100 - alpha
    alpha = alpha * 3
    beta = beta * 3
    return alpha, beta


def get_score(left, right):
    score = 0
    # if(left==0 and right==0):
    #     return 0
    # elif(left==1 and right==1):
    #     return 1
    # elif(left==right):
    #     x=[]
    #     for i in range(100):
    #         x.append(left)
    #     aerfa, beita = get_alpha_beta(left, right)
    #     for i in range(100):
    #         score += get_e(i) / m.e * beta.pdf(x, aerfa, beita)[i]
    #     return score
    if left == right:
        return left
    else:
        aerfa, beita = get_alpha_beta(left, right)
        spacing = (right - left) / 100
        x = np.arange(left, right, spacing)  # 给定的输入数据 [0.0-1]
        for i in range(100):
            score += get_e(i) / m.e * beta.pdf(x, aerfa, beita)[i]
        return score


# def scan_q(case):
#     q = 1
#     length = len(case)
#
#     for i in case:
#         for k in i:
#             if k[0][0] == 0:
#                 k[0][0] = k[0][0]
#             if k[1][0] == 0:
#                 k[1][0] = k[0][0]
#             if k[0][1] == 0:
#                 k[0][1] = k[0][0]
#             if k[1][1] == 0:
#                 k[1][1] = k[0][0]
#             count = 0
#             while (k[0][0] ** q + k[1][0] ** q >= 1 or k[0][1] ** q + k[1][1] ** q >= 1):
#                 q += 1
#                 if count < 40:
#                     count = count + 1
#                 else:
#                     break
#     return q
def Newscore(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    score = ((a ** q + b ** q + ((a + b) / 2) ** q) / 3 - (c ** q + d ** q + ((c + d) / 2) ** q) / 3 + (
            a ** q + b ** q - c ** q - d ** q) / 2
             - m.cos(((a ** q + b ** q) / 2) * 0.5 * (m.pi))
             + m.cos(((c ** q + d ** q) / 2) * 0.5 * (m.pi))) / 3
    return score


def scan_q(case):
    q = 1
    length = len(case)

    for i in case:
        for k in i:
            if k[0][0] == 0:
                k[0][0] = k[0][0] + 0.00001
            if k[1][0] == 0:
                k[1][0] = k[0][0] + 0.0001
            if k[0][1] == 0:
                k[0][1] = k[0][0] + 0.01
            if k[1][1] == 0:
                k[1][1] = k[0][0] + 0.01
            count = 0
            while (k[0][0] ** q + k[1][0] ** q >= 1 or k[0][1] ** q + k[1][1] ** q >= 1):
                q += 1
                if count < 20:
                    count = count + 1
                else:
                    break
    return q

def getRandom01(exp):
    '''
        U=V的情况
        随机一个实数
        '''
    score=[]
    for i in range(exp):
        a = rm.randint(0, exp/2)
        score.append((getpoint0([[a/exp,a/exp],[a/exp,a/exp]]),a/exp,a/exp))
    return score

def getRandom02(exp):
    '''
    U=V的情况
    随机两个区间值端点
    '''
    score=[]
    for i in range(exp):
        a = rm.randint(0, exp/2)
        b = rm.randint(a, exp/2)
        score.append((getpoint0([[a/exp,b/exp],[a/exp,b/exp]]),a/exp,b/exp))
    return score

def getRandom03(exp):
    '''
    随机四个数
    '''
    score=[]
    for i in range(exp*10):
        while True:
            a = rm.randint(0, exp)
            b = a
            c = rm.randint(0, exp)
            d = c
            if(b+d<=exp):
                break
        IVq_ROF=[[a/exp,b/exp],[c/exp,d/exp]]
        score.append((getpoint(IVq_ROF),a/exp,c/exp))
    return score

def getRandom04(exp):
    '''
    随机产生犹豫度相同的模糊集
    '''
    sum_u = rm.randint(0, exp)
    sum_v = rm.randint(0, exp)
    a= rm.randint(0, sum_u)
    b= sum_u-a
    c= rm.randint(0,sum_v)
    d= sum_v-c
    print(a,b,c,d)
    score=[]
    for i in range(exp):
        b=b-i
        a=a+i
        c=c+i
        d=d-i
        if((b-a)<0 or(d-c)<0):
            break
        else:
            s=getpoint0(a / exp, b / exp, c / exp, d / exp)
            print(s)
            score.append((s,a/exp,b/exp,c/exp,d/exp))


def getRandom05(exp):
    '''
    随机四个数
    '''
    score = []
    for i in range(exp * 10):
        while True:
            a = rm.randint(0, exp)
            b = rm.randint(a, exp)
            c = rm.randint(0, exp)
            d = rm.randint(c, exp)
            if (b + d <= exp):
                break
        IVq_ROF = [[a / exp, b / exp], [c / exp, d / exp]]
        score.append((GMscore(IVq_ROF, 1), round(getpoint2(IVq_ROF, 1), 4), (a / exp, b / exp, c / exp, d / exp)))
    return score


def testScore(score, dis):
    k = 0
    for i in range(len(score)):
        for j in range(i + 1, len(score)):
            if (abs(score[i][0] - score[j][0]) <= dis and score[i][2][0] != score[j][2][0]):
                k = k + 1
                print(score[j][0], score[i][0], score[j][1], score[i][1], score[j][2], score[i][2])
    return k


if __name__ == "__main__":
    for i in range(10):
        score = getRandom05(100)
        k = testScore(score, 0)
